#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Filename: college_dump.py
# LD (2009/09/29)
import os
##默认的备份list路径 (确定目录有写权限)
backup_path = '/root/college/new'
mysql_user = 'wgz' #Mysql用户，留空则不进行数据库保存，使用root可以避免权限问题
mysql_pass = '123456' #上面指定用户的密码
mysql_db = ['core_auth', 'kkyoo_account', 'kkyoo_admin', 'kkyoo_gift', 'kkyoo_grade', 'kexoo_im', 'kkyoo_kbao', 'kkyoo_kcard', 'kkyoo_rank', 'kkyoo_rooms', 'kkyoo_storage', 'kkyoo_store'] #数据库，可以多个，保证上面那个用户有权限
mysql_cmd = '`which mysqldump`' #不同系统可能有所不同，尤其是自己编译的
# 也可自己加入路径，如： '/usr/bin/mysqldump'
mysql_charset = 'utf8' #数据库编码
####################

for i in range(len(mysql_db)):
		db_name=backup_path+os.sep+mysql_db[i]+'_new'+'.sql'
		db_command="%s -u%s -p%s --default-character-set=%s --add-drop-table --add-locks -c -l --opt -R %s > %s" % \
				(mysql_cmd,mysql_user,mysql_pass,mysql_charset,mysql_db[i],db_name)
		if os.system(db_command) == 0:
			print "Dump Database %s" %(mysql_db[i])
		else: 
			print "Failed Database %s" %(mysql_db[i])

print "DATABASE DUMP OVER!"
#FILE DONE